/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package db.myibat.data;

import java.io.IOException;
import java.io.Reader;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

/**
 *
 * @author cc
 */
public class _SqlMapConfigReader {

    private  static SqlSessionFactory mySqlSessionFactory = null;

    public static SqlSessionFactory getSqlSessionFactory() {
        if (mySqlSessionFactory == null) {
            Reader reader = null;
            try {
                String resource = "db/myibat/data/_SqlMapConfig.xml";
                reader = Resources.getResourceAsReader(resource);
                SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
                mySqlSessionFactory = builder.build(reader);
                //mySqlSession = factory.openSession();
            } catch (Exception e) {
                throw new RuntimeException("Error in getting the sqlSession object." + e, e);
            } finally {
                if (reader != null) {
                    try {
                        reader.close();
                    } catch (IOException e) {
                    }
                }
            }
        }//end of if
        return mySqlSessionFactory;
    }
}
